import cv2
cap = cv2.VideoCapture("../images/input_video.mp4")
if not cap.isOpened():
    print("无法打开视频文件")
    exit()
frame_count = 0     # 总帧数
save_count = 0      # 保存的帧数
while cap.isOpened():
    ret, frame = cap.read()
    if not ret:
        break
    if frame_count % 30 == 0:       # 每30帧图像保存一帧
        cv2.imwrite(f"frame_{save_count}.jpg", frame)
        save_count += 1
        print(f"已保存 frame_{save_count}.jpg")
    # 记录总帧数
    frame_count += 1

# 4. 释放资源
cap.release()
print(f"抽帧完成，总共保存{save_count}帧")